package com.wqh.feign.controller;

import com.wqh.feign.domain.User;
import com.wqh.feign.service.UserRafactorService;
import com.wqh.feign.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.List;

/**
 * @author wanqh
 * @date 2018/01/16 9:49
 * @description:
 */
@RestController
public class FeignConsumerController {

    private final Logger logger = LoggerFactory.getLogger(FeignConsumerController.class);

    @Autowired
    private UserService userService;

    @Autowired
    private UserRafactorService userRafactorService;

    @GetMapping(value = "/feign_consumer/find")
    public List<User> findAllUser(){
        return userService.findAll();
    }
    @GetMapping("/testFeign")
    public void testFeign() throws UnsupportedEncodingException {
        User user = userService.finUserById(2L);
        logger.info(">>>>>>>>>>>>Request参数：{}>>>>>>>>>>>>>",user);
        User user2 = userService.findUserHeader(URLEncoder.encode("呜呜呜呜","UTF-8"), 3L,1000);
        logger.info(">>>>>>>>>>>>Header:{}>>>>>>>>>>>>>",user2);
        User save_user = new User(5L,"嘻嘻嘻",56);
        User users = userService.insertUser(save_user);
        logger.info(">>>>>>>>>>>>RequestBody:{}>>>>>>>>>>>>>",users);
    }

    @GetMapping("/testRafactorService")
    public void testRafactorService() throws UnsupportedEncodingException {
        com.wqh.api.dto.User user = userRafactorService.finUserById(2L);
        logger.info(">>>>>>>>>>>>Rafactor Request参数：{}>>>>>>>>>>>>>",user);
        com.wqh.api.dto.User user2 = userRafactorService.findUserHeader(URLEncoder.encode("呜呜呜呜","UTF-8"), 3L,1000);
        logger.info(">>>>>>>>>>>>Rafactor Header:{}>>>>>>>>>>>>>",user2);
        com.wqh.api.dto.User save_user = new com.wqh.api.dto.User(5L,"嘻嘻嘻",56);
        com.wqh.api.dto.User users = userRafactorService.insertUser(save_user);
        logger.info(">>>>>>>>>>>>Rafactor RequestBody:{}>>>>>>>>>>>>>",users);
    }
}
